import httpInstance from "@/api/http.js";

export function download(absolutePath){
    let a = document.createElement(`a`);
    a.href = `${httpInstance.defaults.baseURL}/file/download?absolutePath=${encodeURI(absolutePath)}`;
    a.click()
}

export function downloadZip(absolutePathList){
    let a = document.createElement(`a`);
    a.href = `${httpInstance.defaults.baseURL}/file/downloadZip?absolutePathList=${encodeURI(absolutePathList)}`;
    a.click()
}

export function parallelDownloadZip(absolutePathList) {
    let a = document.createElement(`a`);
    a.href = `${httpInstance.defaults.baseURL}/file/compressedDownloadZip?absolutePathList=${encodeURI(absolutePathList)}`;
    a.click()
}

export function list(path,name) {
    return httpInstance({
        url: '/file/list',
        method: 'get',
        params: {path, name}
    })
}

export function icon(absolutePath) {
    return `${httpInstance.defaults.baseURL}/file/icon?absolutePath=${encodeURI(absolutePath)}`
}

export function preview(absolutePath) {
    return `${httpInstance.defaults.baseURL}/file/preview?absolutePath=${encodeURI(absolutePath)}`
}

export function openZipFile(absolutePath,fileName) {
    return `${httpInstance.defaults.baseURL}/file/openZipFile?absolutePath=${encodeURI(absolutePath)}&fileName=${encodeURI(fileName)}`
}

export function downloadZipFile(absolutePath,fileName) {
    let a = document.createElement(`a`);
    a.href = openZipFile(absolutePath,fileName)
    a.click()
}

export function previewZip(absolutePath,directoryName) {
    if(!directoryName) directoryName = ''
    return httpInstance({
        url: `/file/previewZip`,
        method: 'get',
        params: {absolutePath,directoryName}
    })
}

export function info(absolutePathList) {
    return httpInstance({
        url: `/file/info?absolutePathList=${encodeURI(absolutePathList)}`,
        method: 'get',
    })
}

export function text(absolutePath) {
    return httpInstance({
        url: `/file/text?absolutePath=${encodeURI(absolutePath)}`,
        method: 'get',
    })
}